import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';

import { CommonHttpService } from './common/common-http-service';
@Injectable()
export class ApplicantService extends CommonHttpService{
    constructor(public httpClient: HttpClient
    ) {
        super(httpClient);
        console.log(httpClient);
    }
    /**
     * 微信授权
     */
    public getAuth(): Observable<any> {
      let url = `account/wxAuth`;
      // let url2='https://www.proxy.com/connect/oauth2/authorize?appid=wx15ee40ad12e910a5&redirect_uri=http%3A%2F%2F77u7ff.natappfree.cc%2Fhan%2Fwxauth%2FwxLogin&response_type=code&scope=snsapi_userinfo&state=1&connect_redirect=1#wechat_redirect';
      return this.get1(url);
    }

    public freshToken(user_id:string):Observable<any>{
      let url=`account/${user_id}/freshToken`;
      return this.get1(url);
    }

  public freshToken1():Observable<any>{
    // let user_id=localStorage.getItem('id');
    let user_id =JSON.parse(localStorage.getItem('options')).id;
    let url=`account/${user_id}/freshToken`;
    return this.get1(url);


  }

    public getUsrInfo(url: string, code: string):Observable<any>{
      return this.get2(url, code);
    }


    public freshTokenn(){
      this.freshToken1().subscribe(resp=>{
        if (resp.data!==null&& resp.code==200){
          localStorage.setItem("token",resp.data);
          alert("Token过期，请刷新后再试")
        }
      },error2 => {
        console.log(error2);
        alert("Token非法，请确认后再试")
      });
    }
}
